﻿#ifndef CZoomChartView_H
#define CZoomChartView_H
/********************************************************************************
** @ Date:2025/11/11
** @ Author: HanJiaXin
** @ Description:可所发的chatview
** @ Version:1.0.0
** @ ClassName:CZoomChartView
** @ Fun:
********************************************************************************/
#include <QtCharts/QChartView>
#include <QWidget>
#include <QWheelEvent>
#include <QTimer>

QT_CHARTS_USE_NAMESPACE

class CZoomChartView : public QChartView
{
	Q_OBJECT

public:
	explicit CZoomChartView(QWidget *parent = nullptr);
	explicit CZoomChartView(QChart *chart, QWidget *parent = nullptr);

	// 手动控制缩放的方法
	void zoomIn();
	void zoomOut();
	void resetZoom();

protected:
	void wheelEvent(QWheelEvent *event) override;
	void mousePressEvent(QMouseEvent *event) override;
	void mouseMoveEvent(QMouseEvent *event) override;
	void mouseReleaseEvent(QMouseEvent *event) override;
	void mouseDoubleClickEvent(QMouseEvent *event) override;

private slots:
	void completeZoom();

private:
	bool m_isDragging;
	QPoint m_lastMousePos;
	QPointF m_zoomCenter;
	qreal m_zoomFactor;
	QTimer *m_zoomTimer;
	bool m_zoomInProgress;

	void performZoom(qreal factor, const QPointF &centerPoint);
	QPointF getValidChartPoint(const QPoint &pos);
};

#endif